package org.example.service.topic;

import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.boot.CommandLineRunner;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import java.util.stream.IntStream;

/**
 * @author Tang
 * @classname DirectSender
 * @description [  ]
 * @date 2023/4/10 22:06
 */
//@Component
public class TopicSender implements CommandLineRunner {

    @Resource
    RabbitTemplate rabbitTemplate;

    @Override
    public void run(String... args) throws Exception {
        IntStream
                .range(0,10)
                .forEach((index) -> {
                    rabbitTemplate.convertAndSend("bus-exchange",
                            "1.bus1.1", "bus msg 1 " + index);
                    rabbitTemplate.convertAndSend("bus-exchange",
                            "2.bus2.2", "bus msg 2 " + index);
                });
    }

}
